﻿using Data;
using Hero;
using Logic;
using UnityEngine;

namespace Level.Bonuses
{
    public class Life : MonoBehaviour
    {
        public int Value { get; set; }
        private GameSceneData _data;
        private HeroHealth _heroHealth;
        private HeroScore _heroScore;

        public void Construct(GameSceneData data, HeroScore heroScore, HeroHealth heroHealth)
        {
            _data = data;
            _heroScore = heroScore;
            _heroHealth = heroHealth;
        }

        private void OnTriggerEnter(Collider other)
        {
            if (!other.CompareTag(Constants.PlayerTag)) 
                return;
            _heroHealth.Current++;
            _heroScore.SetScore(Value);
            _data.LootPieces.Remove(gameObject);
            Destroy(gameObject);
        }
    }
}
